﻿using HalconDotNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HalconExtension.Models
{
    public abstract class HObjBase
    {
        /// <summary>
        /// HS组件主题
        /// </summary>
        public HSmartWindowControlWPF WindowControlWPF { get; set; }

        public HDrawingObject DrawingObject { get; set; }

        /// <summary>
        /// 资源路径
        /// </summary>
        public string ResourcesPath { get => AppDomain.CurrentDomain.BaseDirectory + "Resources"; }

        /// <summary>
        /// 导出路径
        /// </summary>
        public string OutputPath
        {
            get
            {
                var path = AppDomain.CurrentDomain.BaseDirectory + "Output";
                //如果不存在就创建
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                return path;
            }
        }

        public HImage Image { get; set; }

        public HObject ROI = new HObject();


        public HTuple HType { get; set; }


        /// <summary>
        /// 显示图像
        /// </summary>
        public void Show()
        {
            WindowControlWPF.HalconWindow.AttachDrawingObjectToWindow(DrawingObject);
        }


        /// <summary>
        /// 分离图像
        /// </summary>
        public void Close()
        {
            WindowControlWPF.HalconWindow.DetachDrawingObjectFromWindow(DrawingObject);
        }

        /// <summary>
        /// 保留两位小数
        /// </summary>
        /// <returns></returns>
        public string TwoDecimalPlaces(HTuple value)
        {
            return decimal.Round(decimal.Parse(value.ToString()), 2).ToString();
        }

        /// <summary>
        /// 序列化
        /// </summary>
        /// <returns></returns>
        public abstract override string ToString();

        /// <summary>
        /// 刷新事件
        /// </summary>
        public abstract void Reflash(HDrawingObject drawid, HWindow window, string type);


        /// <summary>
        /// 截取图片
        /// </summary>
        public abstract HObject Reduce();

        /// <summary>
        /// 绘制图案
        /// </summary>
        public abstract Task Draw(Action callback);

        /// <summary>
        /// 取消绘制
        /// </summary>
        public void CancelDraw()
        {
            HalconAPI.CancelDraw();
        }
    }
}
